﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SPMonster2010
{
    public class SPMData
    {
        public static bool IsFieldEditableInSP2010(SPField spField)
        {
            SPList spList = spField.ParentList;

            SPFieldLookup fldLookup = spField as SPFieldLookup;
            bool bCountRelated = fldLookup != null && fldLookup.CountRelated;
            bool bMcolLookup = fldLookup != null && fldLookup.IsDependentLookup &&
                                            fldLookup.LookupList != "Docs";

            SPFieldType t = spField.Type;
            if (t == SPFieldType.Computed ||
                t == SPFieldType.File ||
                t == SPFieldType.Recurrence ||
                t == SPFieldType.CrossProjectLink ||
                t == SPFieldType.AllDayEvent ||
                spField.ReadOnlyField)
            {
                return false;
            }

            if (!spField.Reorderable &&
                !bCountRelated &&
                !(spField.ReadOnlyField && spField.Type == SPFieldType.User) &&
                !(bMcolLookup && !spField.Hidden) &&
                !spList.HasExternalDataSource)
            {
                return false;
            }


            if ((spField.ReadOnlyField && !bCountRelated && !bMcolLookup) ||
                spList.HasExternalDataSource)
            {
                if (spField.Type == SPFieldType.Calculated || spField.Type == SPFieldType.User)
                    return true;

            }
            else
                return true;

            return false;
        } 
    }

    public struct SPMData_ItemCollection
    {
        public SPList list;
        public string[] ItemIDs;

        public SPMData_ItemCollection(string _siteID, string _webID, string _listID, string[] _itemIDs)
        {
            SPSite sitecol = new SPSite(new Guid(_siteID));
            SPWeb web = sitecol.AllWebs[new Guid(_webID)];
            SPList list = web.Lists[new Guid(_listID)];
            this.list = list;
            this.ItemIDs = _itemIDs;

        }
    }


}
